var app = new Vue({
    el: "#deliveryDetail",
    data() {
        return {
            deliveryType: 0, // 配送中：0，已完成：1
            deliveryData: null,
            deliveryTitle: [
                {
                    title: '配送详情'
                },
                {
                    title: '完成配送详情'
                }
            ],
            errMsg: ''
        }
    },
    created () {
        this.getDeliveryData()
    },
    methods: {
        // 返回
        goback () {
            window.location.href = "./deliveryTasklist.html?id=" + this.deliveryType
        },
        getDeliveryData () {
            let id = getUrlParam('id')
            Axios.post('delivery/getDeliveryTaskDetails.do', {ordersId: id})
                .then(res => {
                    if (res.respCode === 'S') {
                        let info = res.data
                        info.createTime = new Date(info.createTime).Format('yy-MM-dd hh:mm')
                        info.boxTime = new Date(info.boxTime).Format('yy-MM-dd hh:mm')
                        if (info.deliveryFinishTime) {
                            info.deliveryFinishTime = new Date(info.deliveryFinishTime).Format('yy-MM-dd hh:mm')
                        }
                        if (info.actualArriveTime) {
                            info.actualArriveTime = new Date(info.actualArriveTime).Format('yy-MM-dd hh:mm')
                        }
                        if (info.communityStatus === 'DELIVER_FINISHED') {
                            this.deliveryType = 1
                        }
                        this.deliveryData = info
                    }
                })
        },
        btnSumbit () {
            let id = getUrlParam('id')
            Axios.post('delivery/updateFinishedStatus.do', {ordersId: id})
                .then(res => {
                    if (res.respCode === 'S') {
                        this.errMsg = '已完成配送！'
                        setTimeout(() => {
                            this.errMsg = ''
                            window.history.go(-1)
                        }, 1500);
                    }
                })
        }
    }
})